package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BasePageInfo;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.MarketComment;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.service.admin.AdminCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :rain
 * @description list?page=1&limit=20&sort=add_time&WXUserIndexVo=desc
 * @since 2022/06/27 16:12
 */
@RestController
@RequestMapping("admin/comment")
public class AdminComment {

    @Autowired
    AdminCommentService adminCommentService;

    /**
     * @param info 分页信息
     * @return 获取评论的内容
     */
    @RequestMapping("list")
    public BaseRespVo list(String userId, String valueId, BasePageInfo info) {
        CommonData<MarketComment> commonData = adminCommentService.queryCommentInfo(userId, valueId, info);
        if (commonData == null){
            BaseRespVo baseRespVo = new BaseRespVo();
            baseRespVo.setErrmsg("参数值不正确!");
            baseRespVo.setErrno(402);
            return baseRespVo;
        }
        return BaseRespVo.ok(commonData);
    }

    /**
     *
     * @param marketComment 删除评论操作
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketComment marketComment) {
        Integer affactRows = adminCommentService.deleteInfoById(marketComment);
        if (affactRows > 0) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.invalidData();
    }
}
